﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
#if DOT_NET
using Microsoft.VisualStudio.TestTools.UnitTesting;
#else
using Microsoft.VisualStudio.TestPlatform.UnitTestFramework;
#endif
using StyleMVVM.DependencyInjection;
using StyleMVVM.DependencyInjection.Conditions;
using StyleMVVM.UnitTests.TestClasses.Conditions;
using StyleMVVM.UnitTests.TestClasses.MultipleImport;

namespace StyleMVVM.UnitTests.DependencyInjection
{
	[TestClass]
	public class StandardConditionTests
	{
		[TestMethod]
		public void WhenInjectedInto()
		{
			Bootstrapper bootstrapper = new Bootstrapper();

			bootstrapper.Container.Register<SomeImpl1>()
			            .As<ISomeInterface>()
			            .WhenInjectedInto<InjectionInstanceOne>();

			bootstrapper.Container.Register<SomeImpl2>()
			            .As<ISomeInterface>()
			            .WhenInjectedInto<InjectionInstanceTwo>();

			bootstrapper.Container.Register<InjectionInstanceOne>().As<InjectionInstanceOne>().ImportProperty(x => x.Impl);
			bootstrapper.Container.Register<InjectionInstanceTwo>().As<InjectionInstanceTwo>().ImportProperty(x => x.Impl);

			bootstrapper.Start();

			InjectionInstanceOne injectionOne = bootstrapper.Container.Locate<InjectionInstanceOne>();

			Assert.IsNotNull(injectionOne);
			Assert.IsInstanceOfType(injectionOne.Impl, typeof(SomeImpl1));

			InjectionInstanceTwo injectionTwo = bootstrapper.Container.Locate<InjectionInstanceTwo>();

			Assert.IsNotNull(injectionTwo);
			Assert.IsInstanceOfType(injectionTwo.Impl, typeof(SomeImpl2));

			bootstrapper.Shutdown();
		}
	}
}